///////Public Sub DeleteItem_Inventory()\\\\\\\

On Error Resume Next

Adodc4.Refresh
Adodc4.Refresh

If Adodc4.Recordset.RecordCount <> 0 Then
Adodc4.Recordset.MoveFirst

        Do
        
                If Label2 = Adodc4.Recordset.Fields(0).Value Then
                    Adodc4.Recordset.Fields("StockOnHand").Value = Adodc4.Recordset.Fields("StockOnHand").Value - Val(Text1)
                    Adodc4.Recordset.Fields("Additional").Value = Adodc4.Recordset.Fields("Additional").Value - Val(Text1)
                
                Adodc4.Recordset.MoveNext
                Exit Sub
                
                Else
                Adodc4.Recordset.MoveNext
                    If Adodc4.Recordset.EOF Then
                        Exit Sub
                    End If
                End If
                
        Loop
        
End If

End Sub


///////Public Sub EditInventoryAdditional()\\\\\\\
On Error Resume Next

Adodc4.Refresh
Adodc4.Refresh

If Adodc4.Recordset.RecordCount <> 0 Then
Adodc4.Recordset.MoveFirst

    Do
        

        If Label2 = Adodc4.Recordset.Fields(0).Value And Adodc4.Recordset.Fields("Additional") <> 0 Then
            
                If Val(Text1) > Val(Label15) Then
                Label16 = Text1 - Label15
                    Adodc4.Recordset.Fields("StockOnHand").Value = Adodc4.Recordset.Fields("StockOnHand").Value + Val(Label16)
                    Adodc4.Recordset.Fields("Additional").Value = Adodc4.Recordset.Fields("Additional").Value + Val(Label16)
                    Adodc4.Recordset.Fields("ItemCode").Value = Label2
                    Adodc4.Recordset.Fields("Description").Value = Label3
                    Adodc4.Recordset.Fields("Size").Value = Label4
                    Adodc4.Recordset.MoveNext
                Exit Sub
                End If
                If Val(Text1) < Val(Label15) Then
                Label16 = Label15 - Text1
                    Adodc4.Recordset.Fields("StockOnHand").Value = Adodc4.Recordset.Fields("StockOnHand").Value - Label16
                    Adodc4.Recordset.Fields("Additional").Value = Adodc4.Recordset.Fields("Additional").Value - Label16
                    Adodc4.Recordset.Fields("ItemCode").Value = Label2
                    Adodc4.Recordset.Fields("Description").Value = Label3
                    Adodc4.Recordset.Fields("Size").Value = Label4
                    Adodc4.Recordset.MoveNext
                Exit Sub
                End If
            Adodc4.Recordset.MoveNext
        Exit Sub
        
        Else
        Adodc4.Recordset.MoveNext
            If Adodc4.Recordset.EOF Then
                Exit Sub
            End If
        End If
    Loop

End If

End Sub


///////Public Sub EditInventoryEntry()\\\\\\\
On Error Resume Next

Adodc4.Refresh
Adodc4.Refresh

If Adodc4.Recordset.RecordCount <> 0 Then
Adodc4.Recordset.MoveFirst

    Do
        

        If Label2 = Adodc4.Recordset.Fields(0).Value And Adodc4.Recordset.Fields("Additional") = "0" Then
            
                If Val(Text1) > Val(Label15) Then
                Label16 = Text1 - Label15
                    Adodc4.Recordset.Fields("StockOnHand").Value = Adodc4.Recordset.Fields("StockOnHand").Value + Val(Label16)
                    Adodc4.Recordset.Fields("StockEntry").Value = Adodc4.Recordset.Fields("StockEntry").Value + Val(Label16)
                    Adodc4.Recordset.Fields("ItemCode").Value = Label2
                    Adodc4.Recordset.Fields("Description").Value = Label3
                    Adodc4.Recordset.Fields("Size").Value = Label4
                    Adodc4.Recordset.Fields("StockEntry").Value = Val(Text1)
                    Adodc4.Recordset.Fields("Additional").Value = "0"
                    Adodc4.Recordset.Fields("StockIssue").Value = "0"
                    Adodc4.Recordset.MoveNext
                Exit Sub
                End If
                If Val(Text1) < Val(Label15) Then
                Label16 = Label15 - Text1
                    Adodc4.Recordset.Fields("StockOnHand").Value = Adodc4.Recordset.Fields("StockOnHand").Value - Label16
                    Adodc4.Recordset.Fields("StockEntry").Value = Adodc4.Recordset.Fields("StockEntry").Value - Label16
                    Adodc4.Recordset.Fields("ItemCode").Value = Label2
                    Adodc4.Recordset.Fields("Description").Value = Label3
                    Adodc4.Recordset.Fields("Size").Value = Label4
                    Adodc4.Recordset.Fields("StockEntry").Value = Val(Text1)
                    Adodc4.Recordset.Fields("Additional").Value = "0"
                    Adodc4.Recordset.Fields("StockIssue").Value = "0"
                    Adodc4.Recordset.MoveNext
                Exit Sub
                End If
                If Val(Text1) = Val(Label15) Then
                
                    Adodc4.Recordset.Fields("StockOnHand").Value = Adodc4.Recordset.Fields("StockOnHand").Value = Text1
                    Adodc4.Recordset.Fields("ItemCode").Value = Label2
                    Adodc4.Recordset.Fields("Description").Value = Label3
                    Adodc4.Recordset.Fields("Size").Value = Label4
                    Adodc4.Recordset.Fields("StockEntry").Value = Val(Text1)
                    Adodc4.Recordset.Fields("Additional").Value = "0"
                    Adodc4.Recordset.Fields("StockIssue").Value = "0"
                    Adodc4.Recordset.MoveNext
                Exit Sub
                End If
            Adodc4.Recordset.MoveNext
        Exit Sub
        
        Else
        Adodc4.Recordset.MoveNext
            If Adodc4.Recordset.EOF Then
                Exit Sub
            End If
        End If
    Loop

End If

End Sub



///////Public Sub Display()\\\\\\\
Adodc1.Refresh
Adodc1.Refresh
If Adodc1.Recordset.RecordCount <> 0 Then
Adodc1.Recordset.MoveFirst

        Do
        
            If Label14 = Adodc1.Recordset.Fields("SupplierCode") Then
                Adodc1.Recordset.Filter = "SupplierCode = '" & Label14 & "'"
            Exit Sub
            
            Else
            Adodc1.Recordset.MoveNext
                If Adodc1.Recordset.EOF Then
                Adodc1.Recordset.Close
                    Exit Sub
                End If
            End If
            
        Loop
        
End If
End Sub


///////Public Sub SaveInventory()\\\\\\\
On Error Resume Next

Adodc4.Refresh
Adodc4.Refresh

If Adodc4.Recordset.RecordCount <> 0 Then
Adodc4.Recordset.MoveFirst

    Do
        

        If Label2 = Adodc4.Recordset.Fields(0).Value Then
            Adodc4.Recordset.Fields("Additional").Value = Adodc4.Recordset.Fields("Additional").Value + Val(Text1)
            Adodc4.Recordset.Fields("StockOnHand").Value = Adodc4.Recordset.Fields("StockOnHand").Value + Val(Text1)
            
            Adodc4.Recordset.MoveNext
            Adodc4.Recordset.MovePrevious
        Exit Sub
        
        Else
        Adodc4.Recordset.MoveNext
            If Adodc4.Recordset.EOF Then
                Adodc4.Refresh
                Adodc4.Recordset.AddNew
                    Adodc4.Recordset.Fields("ItemCode").Value = Label2
                    Adodc4.Recordset.Fields("Description").Value = Label3
                    Adodc4.Recordset.Fields("Size").Value = Label4
                    Adodc4.Recordset.Fields("StockEntry").Value = Val(Text1)
                    Adodc4.Recordset.Fields("StockOnHand").Value = Val(Text1)
                    Adodc4.Recordset.Fields("Additional").Value = "0"
                    Adodc4.Recordset.Fields("StockIssue").Value = "0"

                    Adodc4.Recordset.Update
                    Adodc4.Refresh
                Exit Sub
            End If
        End If
    Loop
Else
                Adodc4.Refresh
                Adodc4.Recordset.AddNew
                    Adodc4.Recordset.Fields("ItemCode").Value = Label2
                    Adodc4.Recordset.Fields("Description").Value = Label3
                    Adodc4.Recordset.Fields("Size").Value = Label4
                    Adodc4.Recordset.Fields("StockEntry").Value = Val(Text1)
                    Adodc4.Recordset.Fields("StockOnHand").Value = Val(Text1)
                    Adodc4.Recordset.Fields("Additional").Value = "0"
                    Adodc4.Recordset.Fields("StockIssue").Value = "0"
                    Adodc4.Recordset.Update
                    Adodc4.Refresh
End If
End Sub



///////Public Sub clearFields()\\\\\\\\
Label1 = "": Label2 = "": Label3 = "": Label4 = "": _
Text1 = "": DataCombo1 = ""

End Sub


///////Public Sub SaveTransaction()\\\\\\\
On Error Resume Next
If Label1 = "" Or Label2 = "" Or Label3 = "" _
Or Label4 = "" Or Text1 = "" Or DataCombo1 = "" Then
    MsgBox "Please complete the fields.!", vbCritical, "Save Data Failed"
    Command2.Enabled = False
    Exit Sub
End If

Adodc2.Refresh
Adodc2.Refresh
If Adodc2.Recordset.RecordCount <> 0 Then
Adodc2.Recordset.MoveFirst

        Do
        
                If Label1 = Adodc2.Recordset.Fields("TransNo") _
                And Label2 = Adodc2.Recordset.Fields("ItemCode") Then
                    Adodc2.Recordset.Fields("TransNo") = Label1
                    Adodc2.Recordset.Fields("Supplier") = DataCombo1
                    Adodc2.Recordset.Fields("ItemCode") = Label2
                    Adodc2.Recordset.Fields("Description") = Label3
                    Adodc2.Recordset.Fields("Size") = Label4
                    Adodc2.Recordset.Fields("Qty") = Text1
                    
                    Adodc2.Recordset.MoveNext
                    Adodc2.Refresh
                    Adodc2.Refresh
                    Call EditInventoryEntry
                    Call EditInventoryAdditional
                    Call clearFields
                    Call TransID_Autonum
                    Command2.Enabled = False
                    Adodc2.Refresh
                    Adodc2.Refresh
                    Adodc2.Refresh
                    MsgBox "Transaction is Updated", vbInformation, "Successfull"
                Exit Sub
                Else
                Adodc2.Recordset.MoveNext
                    If Adodc2.Recordset.EOF Then
                        Adodc2.Refresh
                        Adodc2.Refresh
                        Adodc2.Recordset.AddNew
                        Adodc2.Recordset.Fields("TransNo") = Label1
                        Adodc2.Recordset.Fields("Supplier") = DataCombo1
                        Adodc2.Recordset.Fields("ItemCode") = Label2
                        Adodc2.Recordset.Fields("Description") = Label3
                        Adodc2.Recordset.Fields("Size") = Label4
                        Adodc2.Recordset.Fields("Qty") = Text1
                        Adodc2.Recordset.Fields("DateReceived") = MainForm.Label2.Caption
                        Adodc2.Recordset.Fields("RecievedBy") = MainForm.Label5.Caption
                        Adodc2.Recordset.Update
                        Adodc2.Refresh
                        Adodc2.Refresh
                        Call SaveInventory
                        Call clearFields
                        Call TransID_Autonum
                        Command2.Enabled = False
                        Adodc2.Refresh
                        Adodc2.Refresh
                        Adodc2.Refresh
                        MsgBox "Transaction Complete", vbInformation, "Successfull"
                        Exit Sub
                    End If
                End If
            
            Loop
            
Else
                        Adodc2.Refresh
                        Adodc2.Refresh
                        Adodc2.Recordset.AddNew
                        Adodc2.Recordset.Fields("TransNo") = Label1
                        Adodc2.Recordset.Fields("Supplier") = DataCombo1
                        Adodc2.Recordset.Fields("ItemCode") = Label2
                        Adodc2.Recordset.Fields("Description") = Label3
                        Adodc2.Recordset.Fields("Size") = Label4
                        Adodc2.Recordset.Fields("Qty") = Text1
                        Adodc2.Recordset.Fields("DateReceived") = MainForm.Label2.Caption
                        Adodc2.Recordset.Fields("RecievedBy") = MainForm.Label5.Caption
                        Adodc2.Recordset.Update
                        Adodc2.Refresh
                        Adodc2.Refresh
                        Call SaveInventory
                        Call clearFields
                        Call TransID_Autonum
                        Command2.Enabled = False
                        Adodc2.Refresh
                        Adodc2.Refresh
                        Adodc2.Refresh
                        MsgBox "Transaction Complete", vbInformation, "Successfull"

            
End If
End Sub


///////Public Sub TransID_Autonum()\\\\\\\

On Error Resume Next

Adodc2.Refresh
Adodc2.Refresh

If Adodc2.Recordset.RecordCount = 0 Then
    Adodc2.Recordset.MoveFirst
        Label1.Caption = "TNO-0000"

Else
    Adodc2.Recordset.MoveLast
        Label1.Caption = "TNO-" & Format(Right(Adodc2.Recordset.Fields("TransNo"), 4) + 1, "0000")
End If

End Sub


///////Private Sub Command1_Click()\\\\\\\

DELETE_ITEM = MsgBox("You are about to delete this record." & vbCrLf & "If you click YES, you won't be able to undo the process." & vbCrLf & "Are you sure you want to delete this record?", vbCritical + vbYesNo, "Confirm Delete")
If DELETE_ITEM = vbYes Then
Adodc2.Recordset.Open
Call DeleteItem_Inventory
Adodc2.Recordset.Delete
Adodc2.Refresh
Adodc2.Refresh
MsgBox "Record is successfully deleted.", vbInformation + vbOKOnly, "ProcessComplete"
Call DeleteItem_Inventory
Call clearFields
Call TransID_Autonum
End If

End Sub


///////Private Sub Command2_Click()\\\\\\\
Call SaveTransaction
End Sub


///////Private Sub Command3_Click()\\\\\\\
Unload Me
End Sub


///////Private Sub DataCombo1_Click(Area As Integer)\\\\\\\
Adodc3.Refresh
Adodc3.Refresh
If Adodc3.Recordset.RecordCount <> 0 Then
Adodc3.Recordset.MoveFirst
    
        Do
        
            If DataCombo1 = Adodc3.Recordset.Fields("CompanyName") Then
                Label14.Caption = Adodc3.Recordset.Fields("SupplierCode")
                Call Display
            Exit Sub
            Else
            Adodc3.Recordset.MoveNext
                If Adodc3.Recordset.EOF Then
                    Exit Sub
                End If
            End If
        
        Loop
        
End If

End Sub


///////Private Sub DataCombo1_KeyPress(KeyAscii As Integer)\\\\\\\
On Error Resume Next
If KeyAscii = 13 Then
DataGrid1.TabAction = dbgColumnNavigation
DataGrid1.SetFocus
Call Display
End If

End Sub


///////Private Sub DataGrid1_KeyPress(KeyAscii As Integer)\\\\\\\
On Error Resume Next
If KeyAscii = 13 Then
Label2 = Adodc1.Recordset.Fields("ItemCode")
Label3 = Adodc1.Recordset.Fields("ItemDescription")
Label4 = Adodc1.Recordset.Fields("Size")
Text1.SetFocus
End If

End Sub


///////Private Sub DataGrid2_KeyPress(KeyAscii As Integer)\\\\\\\
If KeyAscii = 13 Then
    Label1 = Adodc2.Recordset.Fields("TransNo")
    DataCombo1 = Adodc2.Recordset.Fields("Supplier")
    Label2 = Adodc2.Recordset.Fields("ItemCode")
    Label3 = Adodc2.Recordset.Fields("Description")
    Label4 = Adodc2.Recordset.Fields("Size")
    Text1 = Adodc2.Recordset.Fields("Qty")
    Label15 = Adodc2.Recordset.Fields("Qty")
End If
End Sub


///////Private Sub Form_Load()\\\\\\\
Me.Height = 8895
Me.Width = 10710
Left = 3240
Top = 2000
Command2.Enabled = False
DataCombo1 = "Select Supplier here"
Adodc1.Recordset.Close
Text2 = "Search Supplier,ItemCode,Description, DateEntry"
SendKeys "{Home}+{End}"
'Call frmOut.TransID_Autonum
Call TransID_Autonum
End Sub


///////Private Sub Text1_Click()\\\\\\\
Text1 = ""
Command2.Enabled = False
End Sub


///////Private Sub Text1_KeyPress(KeyAscii As Integer)\\\\\\\
On Error Resume Next
If KeyAscii = 13 Then
        If IsNumeric(Text1) = False Then
            MsgBox "Input numbers only.!", vbCritical, "Invalid Input"
            Text1 = "": Text1.SetFocus
            Command2.Enabled = True
            
            Exit Sub
        End If
        If Text1 = "0" Or Text1 = "" Then
            MsgBox "Invalid input.!", vbCritical, "Invalid Input"
            Text1 = "": Text1.SetFocus
            Command2.Enabled = True
        Exit Sub
        End If
Command2.Enabled = True
Command2.SetFocus
End If

End Sub


///////Private Sub Text2_Change()\\\\\\\
GHOTenx = "select * From receivequery where receivequery.dateRECEIVED like '" & Text2 & "%' or receivequery.itemcode like '" & Text2 & "%'or receivequery.description like '" & Text2 & "%'or receivequery.supplier like '" & Text2 & "%'"
Adodc2.RecordSource = GHOTenx
Adodc2.Refresh
End Sub

///////Private Sub Text2_Click()\\\\\\\
Text2 = ""
End Sub

